<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>设备维修</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <link rel="stylesheet" href="../../js/lay-module/step-lay/step.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-card-body" style="padding-top: 40px;">
                    <div class="layui-carousel" id="stepForm" lay-filter="stepForm" style="margin: 0 auto;">
                        <div carousel-item>

                            <div>
                                <form class="layui-form" style="margin: 0 auto;max-width: 460px;padding-top: 40px;">

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">设备编号</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="eid" placeholder="请输入" autocomplete="off"
                                                   lay-reqtext="设备编号不能为空"
                                                   class="layui-input" id="equipment">
                                            <span id="msg" style="color:#F20C00;"></span>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">备注说明:</label>
                                        <div class="layui-input-block">
                                            <textarea id="remark" name="remark" placeholder="维修原因" value=""
                                                      class="layui-textarea"></textarea>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button class="layui-btn" lay-submit lay-filter="formStep">
                                                &emsp;下一步&emsp;
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>

                            <div>
                                <form class="layui-form" style="margin: 0 auto;max-width: 460px;padding-top: 40px;">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">设备编号:</label>
                                        <div class="layui-input-block">
                                            <div id="eid" name="eid" class="layui-form-mid layui-word-aux"></div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">设备类型:</label>
                                        <div class="layui-input-block">
                                            <div id="ename" name="ename" class="layui-form-mid layui-word-aux"></div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">型号:</label>
                                        <div class="layui-input-block">
                                            <div id="model" name="model" class="layui-form-mid layui-word-aux"></div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">品牌:</label>
                                        <div class="layui-input-block">
                                            <div id="brand" name="brand" class="layui-form-mid layui-word-aux"></div>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">规格:</label>
                                        <div class="layui-input-block">
                                            <div id="standards" name="standards"
                                                 class="layui-form-mid layui-word-aux"></div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">车间:</label>
                                        <div class="layui-input-block">
                                            <div id="wsname" name="wsname" class="layui-form-mid layui-word-aux"></div>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">备注:</label>
                                        <div class="layui-input-block">
                                            <div id="remarks" name="remarks"
                                                 class="layui-form-mid layui-word-aux"></div>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button type="button" class="layui-btn layui-btn-primary pre">上一步</button>
                                            <button class="layui-btn" lay-submit lay-filter="formStep2">
                                                &emsp;确认提交&emsp;
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>

                            <div>
                                <div style="text-align: center;margin-top: 90px;">
                                    <i id="ico" class="layui-icon layui-circle" style=""></i>
                                    <div id="tip"
                                         style="font-size: 24px;color: #333;font-weight: 500;margin-top: 30px;">
                                    </div>
                                </div>
                                <div style="text-align: center;margin-top: 50px;">
                                    <button class="layui-btn next">维修申请</button>
<!--                                    <button class="layui-btn layui-btn-primary">查看维修情况</button>-->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['table', 'form', 'tableSelect', 'step'], function () {
        var $ = layui.jquery,
            table = layui.table,
            form = layui.form,
            step = layui.step,
            tableSelect = layui.tableSelect;
        tableSelect.render({
            elem: '#equipment',
            checkedKey: 'id',
            height: '200',
            width: '100',
            searchType: 'more',
            searchList: [
                {searchKey: 'eid', searchPlaceholder: '搜索设备编号'},
                {searchKey: 'state', searchPlaceholder: '搜索设备状态'},
                //{searchKey: 'brand', searchPlaceholder: '搜索设备品牌'},
            ],
            table: {
                url: '/equipment/show',
                cols: [[
                    {type: 'radio'},
                    {field: 'eid', title: '设备编号', templet: '<div>{{d.equipment.eid}}</div>'},
                    {field: 'tid', hide: true, templet: '<div>{{d.equipment.tid}}</div>'},
                    {field: 'ename', title: '设备类型', templet: '<div>{{d.equipmentType.ename}}</div>'},
                    //{field: 'description', title: '描述', templet: '<div>{{d.equipmentType.description}}</div>'},
                    {field: 'model', title: '型号', templet: '<div>{{d.equipment.model}}</div>'},
                    {field: 'brand', title: '品牌', templet: '<div>{{d.equipment.brand}}</div>'},
                    {field: 'standards', title: '规格', templet: '<div>{{d.equipment.standards}}</div>'},
                    {field: 'wsname', title: '车间', templet: '<div>{{d.workShop.wsname}}</div>'},
                    //{field: 'price', title: '价格', templet: '<div>{{d.equipment.price}}</div>'},
                    {field: 'state', title: '状态', templet: '<div>{{d.equipment.state}}</div>'},
                ]],
            },
            done: function (elem, data) {
                var NEWJSON = []
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.equipment.eid)
                })
                //console.log(NEWJSON);
                elem.val(NEWJSON.join(","))
            }
        });

        step.render({
            elem: '#stepForm',
            filter: 'stepForm',
            width: '100%', //设置容器宽度
            stepWidth: '750px',
            height: '500px',
            stepItems: [{
                title: '填写申请信息'
            }, {
                title: '确认提交信息'
            }, {
                title: '完成'
            }]
        });

        form.on('submit(formStep)', function (data) {
            // console.log(data);
            if (data.field.eid == null || data.field.eid =='') {
                $("#msg").html("设备编号不能为空");
                return false;
            }
            $.get("/equipment/show?page=1&limit=10&eid=" + data.field.eid, function (data) {
                console.log(data.data);
                if (data.code != 0) {
                    $("#msg").html(data.msg);
                } else {
                    var equipment = data.data[0].equipment;
                    var equipmentTypoe = data.data[0].equipmentType;
                    var workshop = data.data[0].workShop;
                    $("#eid").html(equipment.eid);
                    $("#ename").html(equipmentTypoe.ename);
                    $("#wsname").html(workshop.wsname);
                    $("#model").html(equipment.model);
                    $("#brand").html(equipment.brand);
                    $("#standards").html(equipment.standards);
                    step.next('#stepForm');
                }
            });
            $("#remarks").html(data.field.remark);
            return false;
        });

        form.on('submit(formStep2)', function (d) {
            //console.log(data);无数据
            var eid = $("#equipment").val();
            var reason = $("#remarks").html();
            $.post("/application/equipment", {eid: eid, reason: reason}, function (data) {
                if (data.code != 0) {
                    $("#ico").attr("style", "color: white;font-size:30px;font-weight:bold;background: #F20C00;padding: 20px;line-height: 80px;");
                    $("#ico").html("&#x1006;")
                } else {
                    $("#ico").attr("style", "color: white;font-size:30px;font-weight:bold;background: #52C41A;padding: 20px;line-height: 80px;");
                    $("#ico").html("&#xe605;")
                }
                $("#tip").html(data.msg);
            });
            step.next('#stepForm');
            return false;
        });

        $('.pre').click(function () {
            step.pre('#stepForm');
        });

        $('.next').click(function () {
            //$.get("/page/equipment/equipmentRepair.html")
            step.next('#stepForm');
        });
    })
</script>
</body>
</html>